package andev.game2048;

import android.view.GestureDetector;
import android.view.MotionEvent;

/**
 * Created by lzy1g on 2015/8/6.
 */
public class GameViewListener extends GestureDetector.SimpleOnGestureListener {
    private GameView gameView;

    public GameViewListener(GameView gameView) {
        this.gameView = gameView;
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        if (Math.abs(velocityX) > Math.abs(velocityY)) {
            if (e2.getX() - e1.getX() > 5) {
                gameView.swipeRight(true);
            }
            if (e2.getX() - e1.getX() < -5) {
                gameView.swipeLeft(true);
            }
        } else {
            if (e2.getY() - e1.getY() > 5) {
                gameView.swipeDown(true);
            }
            if (e2.getY() - e1.getY() < -5) {
                gameView.swipeUp(true);
            }
        }
        return false;
    }

    @Override
    public boolean onDown(MotionEvent e) {
        return true;
    }
}
